import { element, by, browser, $$ } from "protractor";
/**
 * Created by hanzhendong on 2017/1/17.
 */

describe('通讯录：首页', () => {
    it('当开始访问时，浏览器是否成功首页，端口==8100', () => {
        browser.get('/index.html');
        expect(browser.getCurrentUrl()).toMatch(/8100/);
    });
    it('首页标题是否正确', () => {
        browser.driver.sleep(2000);
        expect(browser.getTitle()).toEqual('欢迎');
    });
    it('应该有个nav', () => {
        expect(element(by.css('ion-navbar')).isPresent()).toEqual(true);
    });
    it('+被点击', () => {
        element(by.css('ion-fab > button')).click().then(() => {
            browser.driver.sleep(2000);
            expect(element(by.css('.fab-list-active'))).toBeTruthy();
        });
    });
});
describe('通讯录：搜索', () => {
    it('进入搜索页面', () => {
        element(by.css('.ion-ios-search-outline')).click()
            .then(() => {
                browser.driver.sleep(2000);
                expect(element(by.css('.fab-close-active'))).toBeTruthy();
                expect(element.all(by.css('ion-navbar .toolbar-title-ios')).last().getText()).toEqual('公司领导们');

            });
    });
    it('列表：张志强=》1个结果', () => {
        var searchInput = $$('input[type=search]');
        searchInput.sendKeys('张志强');
        let list = $$('.list-ios > ion-item');
        expect(list.count()).toBe(1);
    });
    it('列表：张三=》0个结果', () => {
        browser.driver.sleep(2000);
        var searchInput = $$('input[type=search]');
        searchInput.clear();
        searchInput.sendKeys('张三');
        browser.driver.sleep(2000);
        let list = $$('.list-ios > ion-item');
        expect(list.count()).toBe(0);
    });
    it('列表：张=》2个结果', () => {
        browser.driver.sleep(2000);
        var searchInput = $$('input[type=search]');
        searchInput.clear();
        searchInput.sendKeys('张');
        browser.driver.sleep(2000);
        let list = $$('.list-ios > ion-item');
        expect(list.count()).toBe(2);
        browser.driver.sleep(2000);
    });
});
describe('通讯录：详细', () => {
    it('详细：张龙=》具体信息', () => {
        browser.findElement(by.partialLinkText('张龙')).click()
            .then(() => {
                browser.driver.sleep(2000);
                expect(element.all(by.css('ion-navbar .toolbar-title-ios')).last().getText()).toEqual('张龙');
            });
    });
});